<html>
<title>昨日涨停开盘买入统计</title>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/fupan_css.css') }}" />
<script src="{{ url_for('static',filename='js/jquery-2.1.1.min.js') }}"></script>
<script src="{{ url_for('static',filename='js/show_message.js') }}"></script>
<script src="{{ url_for('static',filename='js/update.js') }}"></script>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">

<link href="./static/kpl/com.css" rel="stylesheet">
<link href="./static/kpl/fChart.css" rel="stylesheet">
<link href="./static/kpl/mpage.css" rel="stylesheet">
<script src="./static/kpl/jquery.js"></script>
<script src="./static/kpl/com.js"></script>
<!--分时-->
<script src="./static/kpl/floatMChart.js"></script>
<!--K线-->
<script src="./static/kpl/floatKChart.js"></script>
<script src="./static/kpl/fChart.js"></script>

<body>
    <div class="table-one" style="float:left;width:4px;height:100%;overflow:auto;">
        <table id="limit1" cellspacing="0"></table>
    </div>
    <div class="table-one" style="float:left;width:400px;height:100%;">
        <div class="table-one" style="float:left;width:400px;height:30%;overflow:auto;">
            <table id="limit2" cellspacing="0"></table>
        </div>
        <div class="table-one" style="float:left;width:400px;height:70%;overflow:auto;">
            <table id="limit22" cellspacing="0"></table>
        </div>
    </div>
    <div class="table-one" style="float:left;width:20px;height:100%;overflow:auto;">
    </div>
    <div class="table-one" style="float:left;width:400px;height:100%;">
        <div class="table-one" style="float:left;width:400px;height:30%;overflow:auto;">
            <table id="limit3" cellspacing="0"></table>
        </div>
        <div class="table-one" style="float:left;width:400px;height:70%;overflow:auto;">
            <table id="limit33" cellspacing="0"></table>
        </div>
        <!-- <div class="table-one" style="float:left;width:400px;height:50%;overflow:auto;">
            <table id="history33" cellspacing="0"></table>
        </div> -->
    </div>
    <div class="table-one" style="float:left;width:20px;height:100%;overflow:auto;">
    </div>
    <div class="table-one" style="float:left;width:400px;height:100%;">
        <div class="table-one" style="float:left;width:400px;height:30%;overflow:auto;">
            <table id="limit4" cellspacing="0"></table>
        </div>
        <div class="table-one" style="float:left;width:400px;height:70%;overflow:auto;">
            <table id="limit44" cellspacing="0"></table>
        </div>
        <!-- <div class="table-one" style="float:left;width:400px;height:340px;overflow:auto;">
            <table id="history44" cellspacing="0"></table> -->
    </div>
    </div>
    <div class="table-one" style="float:left;width:20px;height:100%;overflow:auto;">
    </div>
    <div class="table-one" style="float:left;width:400px;height:100%;">
        <div class="table-one" style="float:left;width:400px;height:30%;overflow:auto;">
            <table id="limit5" cellspacing="0"></table>
        </div>
        <div class="table-one" style="float:left;width:400px;height:70%;overflow:auto;">
            <table id="limit55" cellspacing="0"></table>
        </div>
    </div>
    <div class="table-one" style="float:left;width:200px;height:340px;overflow:auto;">
        <div>
            <label for="meeting">选择日期：</label>
            <input id="meeting" type="date" onchange="upperCase(this.id)" />
        </div>
        <table id="history" cellspacing="0"></table>
    </div>
</body>

<script type="text/javascript">
    // 获取股票开盘涨幅实体涨幅等数据
    function wencai(search) {
        var m_data = []
        $.ajax({
            url: '/wencai',
            data: { data: search },
            type: 'POST',
            async: false, //同步加载
            dataType: 'json',
            // contentType: 'application/json; charset=UTF-8',
            success: function (data) {
                wencai_data = data;
                console.log(data);
                // set_table2_history(_data, id, caption, data)
            },
            error: function (msg) {
                console.log(msg);
            }
        })
        // return wencai_data;
    };
</script>
<!-- 回调函数 -->
<script type="text/javascript">
    function history_55(data) {
        var stocks55_ = new Array()
        stocks55 = stocks55_
        for (i = 0; i < data['data'].length; i++) {
            stocks55.push(data['data'][i][0])
        }
        if (stocks55.length > 0) {
            get_rise_data_update(stocks55, data, 'history', '历史未涨停的四板个股')
        }
    }

    function history_44(data) {
        var stocks44_ = new Array()
        stocks44 = stocks44_
        for (i = 0; i < data['data'].length; i++) {
            stocks44.push(data['data'][i][0])
        }
        if (stocks44.length > 0) {
            get_rise_data_update(stocks44, data, 'history44', '历史未涨停的三板个股')
        }
    }

    function history_33(data) {
        var stocks33_ = new Array()
        stocks33 = stocks33_
        for (i = 0; i < data['data'].length; i++) {
            stocks33.push(data['data'][i][0])
        }
        if (stocks33.length > 0) {
            get_rise_data_update(stocks33, data, 'history33', '历史未涨停的二板个股')
        }
    }
</script>
<script type="text/javascript">
    // 获取历史日期
    function get_history_date() {
        var m_data = []
        $.ajax({
            url: '/get_history_date',
            // data: {data: codes},
            type: 'POST',
            async: false, //异步加载
            dataType: 'json',
            // contentType: 'application/json; charset=UTF-8',
            success: function (data) {
                m_data = data;
                console.log(data);
            },
            error: function (msg) {
                console.log(msg);
            }
        })
        return m_data;
    };
</script>
<!-- 日期事件 -->
<script type="text/javascript">
    function show_form(date){//date 日期
        // get_limit1_data('oneStocksHistory', date, 'limit1', '一板')
        get_limit1_data('oneStocksYesterdayHistory', date, 'limit2', '二板')
        get_limit2_data('oneBoardStocksYesterdayHistory', date, 'limit22', '未涨停的昨日一板个股')
        get_limit1_data('twoStocksYesterdayHistory', date, 'limit3', '三板')
        get_limit2_data('twoBoardStocksYesterdayHistory', date, 'limit33', '未涨停的昨日二板个股')
        get_limit1_data('threeStocksYesterdayHistory', date, 'limit4', '四板')
        get_limit2_data('threeBoardStocksYesterdayHistory', date, 'limit44', '未涨停的昨日三板个股')
        get_limit1_data('fourStocksYesterdayHistory', date, 'limit5', '更高')
        get_limit2_data('fourBoardStocksYesterdayHistory', date, 'limit55', '未涨停的昨日四板及以上个股')
    }
    function upperCase(x) {
        var dates = document.getElementById(x).value
        data = get_history_date()['data']
        _indexof = data.indexOf(dates, 0)
        _indexof = _indexof - 1
        day = data.length - _indexof-2 //几天的区间涨跌幅
        if(day == 0){
            day = 1
        }
        var search = '去掉ST ' + data[_indexof] + '涨停 ' + dates + '开盘涨幅 ' + dates + '实体涨幅 '+ day+'天的区间涨跌幅'
        wencai(search)
        console.log(search);

        show_form(dates)
    }
</script>

<script type="text/javascript">
    var ID_THREAD = -1; //循环线程
    var all_theme = []; //题材数组
    var stocks55, stocks44, stocks33 = new Array();
    var wencai_data = new Array();

    $(document).ready(function () {
        data = get_history_date()['data']
        document.getElementById('meeting').value = data[data.length-1]//设置日期
        var search = '去掉ST ' + data[data.length-2] + '涨停 ' + data[data.length-1] + '开盘涨幅 ' + data[data.length-1] + '实体涨幅 1天的区间涨跌幅'
        wencai(search)
        console.log(search);
        show_form(data[data.length-1])
    });

    function run() {
        //获取现在日期
        var date = new Date();
        const formatDate = (date) => {
            let formatted_date = date.getFullYear() + "-" + checkDay((date.getMonth() + 1)) + "-" + checkDay(date.getDate())
            return formatted_date;
        }
        console.log(formatDate(date));

        var dates = _history_date(formatDate(date))

    }

    // 获取股票涨幅数据并更新表格
    function get_rise_data_update(codes, _data, id, caption) {
        var m_data = []
        $.ajax({
            url: '/codes_rise',
            data: JSON.stringify({
                data: codes
            }),
            type: 'POST',
            async: true, //异步加载
            dataType: 'json',
            contentType: 'application/json; charset=UTF-8',
            success: function (data) {
                m_data = data;
                console.log(data);
                set_table2_history(_data, id, caption, data)
            },
            error: function (msg) {
                console.log(msg);
            }
        })
        return m_data;
    };

    // 获取涨停数据
    function get_limit1_data(fun, limit, id, caption) {
        var m_data = []
        $.ajax({
            url: '/' + fun,
            data: { 'data': limit },
            type: 'POST',
            async: true, //异步加载
            dataType: 'json',
            success: function (data) {
                m_data = data['data']
                _data = wencai_data['data']['data']
                //确定（开盘涨幅/实体涨幅）索引
                var index_fszf //分时涨幅
                var index_stzf //实体涨幅
                var index_code //股票代码
                var index_qjzf //区间涨幅
                for (var c = 0; c < wencai_data['data']['columns'].length; c++) {
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "分时涨跌幅") {
                        index_fszf = c
                    }
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "实体涨跌幅") {
                        index_stzf = c
                    }
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "code") {
                        index_code = c
                    }
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "区间涨跌幅") {
                        index_qjzf = c
                    }
                }
                for (var i = 0; i < m_data.length; i++) {
                    for (var i1 = 0; i1 < _data.length; i1++) {
                        if (_data[i1][index_code] == m_data[i][0]) {
                            m_data[i].push(parseFloat(_data[i1][index_fszf]).toFixed(2))//分时涨跌幅
                            m_data[i].push(parseFloat(_data[i1][index_stzf]).toFixed(2))//实体涨跌幅
                            m_data[i].push(parseFloat(_data[i1][index_qjzf]).toFixed(2))//区间涨跌幅
                            break
                        }
                        if(i1 == _data.length-1){
                            m_data[i].push('停牌')//分时涨跌幅
                            m_data[i].push('停牌')//实体涨跌幅
                            m_data[i].push('停牌')//区间涨跌幅
                        }
                    }
                }

                set_table1(m_data, id, caption)
                // set_option()
            },
            error: function (msg) {
                console.log(msg);
            }
        })
        return m_data;
    };

    // 获取昨日涨停今日未涨停数据
    function get_limit2_data(fun, limit, id, caption) {
        var m_data = []
        $.ajax({
            url: '/' + fun,
            data: { 'data': limit },
            type: 'POST',
            async: true, //异步加载
            dataType: 'json',
            success: function (data) {
                m_data = data['data']
                _data = wencai_data['data']['data']
                //确定（开盘涨幅/实体涨幅）索引
                var index_fszf //分时涨幅
                var index_stzf //实体涨幅
                var index_code //股票代码
                var index_qjzf //区间涨幅
                for (var c = 0; c < wencai_data['data']['columns'].length; c++) {
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "分时涨跌幅") {
                        index_fszf = c
                    }
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "实体涨跌幅") {
                        index_stzf = c
                    }
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "code") {
                        index_code = c
                    }
                    if (wencai_data['data']['columns'][c].substring(0, 5) == "区间涨跌幅") {
                        index_qjzf = c
                    }
                }
                for (var i = 0; i < m_data.length; i++) {
                    for (var i1 = 0; i1 < _data.length; i1++) {
                        if (_data[i1][index_code] == m_data[i][0]) {
                            m_data[i].push(parseFloat(_data[i1][index_fszf]).toFixed(2))//分时涨跌幅
                            m_data[i].push(parseFloat(_data[i1][index_stzf]).toFixed(2))//实体涨跌幅
                            m_data[i].push(parseFloat(_data[i1][index_qjzf]).toFixed(2))//区间涨跌幅
                            break
                        }
                        if(i1 == _data.length-1){
                            m_data[i].push('停牌')//分时涨跌幅
                            m_data[i].push('停牌')//实体涨跌幅
                            m_data[i].push('停牌')//区间涨跌幅
                        }
                    }
                }
                set_table2(m_data, id, caption)
                // set_option()
            },
            error: function (msg) {
                console.log(msg);
            }
        })
        return m_data;
    };

    // 获取历史昨日涨停今日未涨停数据
    function get_limit2_data_history(fun, limit, id, caption, callback) {
        var m_data = []
        $.ajax({
            url: '/' + fun,
            data: { 'data': limit },
            type: 'POST',
            async: true, //异步加载
            dataType: 'json',
            success: function (data) {
                m_data = data
                callback(data);
            },
            error: function (msg) {
                console.log(msg);
            }
        })
        // return m_data;
    };

    function set_table1(data, id, caption) {
        all_theme = [];
        var m_html = ""
        var m_th = "<tr class=\"cur\">\
            <th style=\"width:14%\">股票名称</th>\
            <th style=\"width:14%\" >涨停时间</th>\
            <th style=\"width:8%\">状态</th>\
            <th>涨停原因</th>\
            <th style=\"width:10%\">开盘%</th>\
            <th style=\"width:10%\">实体%</th>\
            <th style=\"width:10%\">区间%</th>\
            </tr>"
        // <th>板块</th>\
        // <th>最大封单</th>\
        // <th>封单</th>\
        // <th>主力净额</th>\
        // <th>成交额</th>\
        // <th>实际换手</th>\
        // <th>实际流通</th>\

        var m_list = data
        for (var i_row = 0; i_row < m_list.length; i_row++) {
            if (i_row % 2 == 0) {
                m_html += "<tr>"
            } else
                m_html += "<tr class=\"cur\">"
            if (m_list[i_row][16] == 1) {
                m_html += "<td style=\"width:14%\" class=\"gbnews gre td1 over-chart\" data-name=\"" + m_list[i_row][1] + "\" data-sid=\"" + m_list[i_row][0] + "\" data-ct=\"big\">" + m_list[i_row][1] + "</td>" //设置股票的颜色
            } else {
                m_html += "<td style=\"width:14%\" class=\"td1 over-chart\" data-name=\"" + m_list[i_row][1] + "\" data-sid=\"" + m_list[i_row][0] + "\" data-ct=\"big\">" + m_list[i_row][1] + "</td>"
            }
            m_html += "<td>" + format_date(new Date(parseInt(m_list[i_row][4]) * 1000)) + "</td>"
            //     //数据统计
            // all_theme = all_theme.concat({
            //     name: m_list[i_row][5],
            //     value: 1
            // })
            m_html += "<td>" + m_list[i_row][15] + "</td>"
            m_html += "<td>" + m_list[i_row][5] + "</td>"
            //设置涨幅颜色
            if (m_list[i_row][21] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][21] + "</td>"
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][21] + "</td>"
            }
            if (m_list[i_row][22] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][22] + "</td>"
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][22] + "</td>"
            }
            if (m_list[i_row][23] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][23] + "</td>"
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][23] + "</td>"
            }
            m_html += "</tr>"
        }
        var tb = document.getElementById(id); //获取表格的dom节点
        var caption = "<caption align=\"top\">" + caption + "-" + m_list.length + "</caption>"
        tb.innerHTML = caption + m_th + m_html
    }


    function set_table2(data, id, caption) {
        all_theme = [];
        var m_html = ""
        var m_th = "<tr class=\"cur\">\
            <th style=\"width:14%\">股票名称</th>\
            <th style=\"width:16%\">状态</th>\
            <th>板块</th>\
            <th style=\"width:10%\">涨幅%</th>\
            <th style=\"width:10%\">开盘%</th>\
            <th style=\"width:10%\">实体%</th>\
            <th style=\"width:10%\">区间%</th>\
            </tr>"
        // <th>成交额</th>\
        var m_list = data
        for (var i_row = 0; i_row < m_list.length; i_row++) {
            if (i_row % 2 == 0) {
                m_html += "<tr>"
            } else
                m_html += "<tr class=\"cur\">"
            if (m_list[i_row][16] == 1) {
                m_html += "<td class=\"gbnews gre td1 over-chart\" data-name=\"" + m_list[i_row][1] + "\" data-sid=\"" + m_list[i_row][0] + "\" data-ct=\"big\">" + m_list[i_row][1] + "</td>" //设置股票的颜色
            } else {
                m_html += "<td class=\"td1 over-chart\" data-name=\"" + m_list[i_row][1] + "\" data-sid=\"" + m_list[i_row][0] + "\" data-ct=\"big\">" + m_list[i_row][1] + "</td>"
            }
            m_html += "<td>" + m_list[i_row][15] + "</td>"
            m_html += "<td>" + m_list[i_row][6] + "</td>"
            if (m_list[i_row][5] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][5] + "</td>" //设置涨幅的颜色
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][5] + "</td>"
            }
            //设置涨幅颜色
            if (m_list[i_row][17] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][17] + "</td>"
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][17] + "</td>"
            }
            if (m_list[i_row][18] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][18] + "</td>"
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][18] + "</td>"
            }
            if (m_list[i_row][19] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][19] + "</td>"
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][19] + "</td>"
            }
            m_html += "</tr>"
        }
        var tb = document.getElementById(id); //获取表格的dom节点
        var caption = "<caption align=\"top\">" + caption + "-" + m_list.length + "</caption>"
        tb.innerHTML = caption + m_th + m_html
    }

    function set_table2_history(data, id, caption, limit) {
        all_theme = [];
        var m_html = ""
        var m_th = "<tr class=\"cur\">\
            <th>股票名称</th>\
            <th>状态</th>\
            <th>板块</th>\
            <th>昨日涨幅</th>\
            <th>实时涨幅</th>\
            </tr>"
        // <th>成交额</th>\
        var m_list = data['data']
        for (var i_row = 0; i_row < m_list.length; i_row++) {
            if (i_row % 2 == 0) {
                m_html += "<tr>"
            } else {
                m_html += "<tr class=\"cur\">"
            }
            if (m_list[i_row][16] == 1) {
                m_html += "<td class=\"gbnews gre td1 over-chart\" data-name=\"" + m_list[i_row][1] + "\" data-sid=\"" + m_list[i_row][0] + "\" data-ct=\"big\">" + m_list[i_row][1] + "</td>" //设置股票的颜色
            } else {
                m_html += "<td class=\"td1 over-chart\" data-name=\"" + m_list[i_row][1] + "\" data-sid=\"" + m_list[i_row][0] + "\" data-ct=\"big\">" + m_list[i_row][1] + "</td>"
            }
            m_html += "<td>" + m_list[i_row][15] + "</td>"
            m_html += "<td>" + m_list[i_row][6] + "</td>"
            // m_html += "<td>" + limit[m_list[i_row][0]]["涨跌(%)"] + "</td>"
            if (m_list[i_row][5] < 0) {
                m_html += "<td class=\"gbnews gre\">" + m_list[i_row][5] + "</td>" //设置涨幅的颜色
            } else {
                m_html += "<td class=\"red\">" + m_list[i_row][5] + "</td>"
            }
            if (limit[m_list[i_row][0]]["涨跌(%)"] < 0) {
                m_html += "<td class=\"gbnews gre\">" + limit[m_list[i_row][0]]["涨跌(%)"] + "</td>" //设置股票名称的颜色
            } else {
                m_html += "<td class=\"red\">" + limit[m_list[i_row][0]]["涨跌(%)"] + "</td>"
            }

            // m_html += "<td>" + format_money(m_list[i_row][10]) + "</td>"
            m_html += "</tr>"
        }
        var tb = document.getElementById(id); //获取表格的dom节点
        var caption = "<caption align=\"top\">" + caption + "-" + m_list.length + "</caption>"
        tb.innerHTML = caption + m_th + m_html
    }

</script>

</html>